var orderDesc;

$(function () {
    orderDesc = new Vue({
        el:'#orderDescController',
        data:{
            id:_id,
            item:{},
            orderConfirm:false,
            showPayType:false,
            payType:1
        },
        methods:{
            loadData:function () {
                var that = this;
                sy.postApi('/api/userInfo/getDetail',{id:_id},function (data) {
                    var price = data.finalPrice;
                    price = Number(price);
                    if (data.bailPrice){
                        price = price.subtract(data.bailPrice);
                        price = Number(price);
                    }
                    if (data.vipServicePay){
                        price = price.add(data.vipServicePay);
                        price = Number(price);
                    }else{
                        price = price.add(data.servicePay);
                        price = Number(price);
                    }
                    if (data.packMoney){
                        price = price.add(Number(data.packMoney));
                        price = Number(price);
                    }
                    if (data.expressMoney){
                        price = price.add(Number(data.expressMoney));
                        price = Number(price);
                    }
                    data.price = price;
                    that.item = data;
                })
            },
            cancelOrder:function () {
                var that = this;
                sy.postApi('/api/userInfo/cancelOrder',{
                    id:_id
                },function (data) {
                    that.loadData();
                })
            },
            setOrderConfirm:function (data) {
                this.orderConfirm = data;
            },
            confirmOrder:function () {
                var that = this;
                sy.postApi('/api/userInfo/confirmOrder',{
                    id:_id
                },function (data) {
                    that.setOrderConfirm(false);
                    that.loadData();
                })
            },
            express:function () {
                sy.postApi('/api/userInfo/getExpressInfo',{
                    orderId:_id
                },function (data) {
                    layer.open({
                        title:null,
                        type: 2,
                        content: [data, 'no'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                        area: ['320px', '600px'],
                        shadeClose:true
                    });
                })
            },
            showPay:function (order) {
                this.showPayType = true;
            },
            toPay:function (payType) {
                payType = this.payType;
                sy.post('/web/pay/order/'+_id,{
                    payType:payType
                },function (data) {
                    if (data.errorCode){
                        sy.msg(data.errorMsg);
                        return;
                    }
                    if (payType == 1){
                        //支付宝
                        $("#content").val(data.pay);
                        $("#form").submit();
                    }else{
                        //微信二维码
                        var url = sy.path + '/qr?msg='+data.qr+'&size=150';
                        sy.showWxQrPay(data.price,url,function(){window.location.href = sy.path + "/web/home/order";},null);
                    }
                })
            },
            selectPayType:function (type) {
                this.payType = type;
            },
            setType:function (value) {
                this.showPayType  =value;
            },
        },
        created:function () {
            this.loadData();
        }
    });
});